package kr.memo.controller;

import kr.memo.dao.MemoDao;
import kr.memo.domain.MemoCommand;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MemoUpdateController {

	@Autowired
	private MemoDao memoDao;
	
	@RequestMapping(value="updateMemo.do", method=RequestMethod.GET)
	public ModelAndView form(@RequestParam("memo_no")int memo_no){
			MemoCommand memoCommand = memoDao.selectMemo(memo_no);
			
		return new ModelAndView("updateFormMemo","memoCommand",memoCommand);
	}
	@RequestMapping(value="updateMemo.do", method=RequestMethod.POST)
	public String form(@ModelAttribute("memoCommand")MemoCommand memoCommand){
			memoDao.updateMemo(memoCommand);
			
		return "redirect:/memoList.do?p_num="+memoCommand.getP_num();
	}
	
	
	
}
